﻿#ifndef UDPSERVER_H
#define UDPSERVER_H

#include <QUdpSocket>
#include <QSettings>


class UdpServer : public QObject
{
    Q_OBJECT
public:
    explicit UdpServer(QSettings* settings, QObject *parent = nullptr);
    ~UdpServer();

private:
    void init();
    void fetch();
    void trainStart();

private:
    // INI配置文件
    QSettings *m_settings;

    // UDP通信及参数
    QUdpSocket *m_udpSocket;
    QHostAddress m_localHost;
    quint16 m_localPort;
    QHostAddress m_remoteHost;
    quint16 m_remotePort;

    // 接收缓存
    QByteArray m_recvBuffer;

signals:
    void sigReadFinished(const QByteArray& data);
    void sigCourseTrain(const QString courseNumber);

public slots:
    void onListen();
    void onRead();
    void onWrite(const QByteArray data);
    void onHeartBeat();
    void onTrainEnd();
    void onStepNotify(const QString stepCode);
    void onFaultNotify(const QString faultCode, const int result);
    void onCourseScore();

};

#endif // UDPSERVER_H
